<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/css/common.css" />
		<link rel="stylesheet" type="text/css" href="/js/flatpickr.min.css" />
		<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.7/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="/dialog/css/dialog.css" />
		<link rel="stylesheet" type="text/css" href="/css/font-awesome.css" />
	</head>

	<body>
		<!--顶部导航 -->
		<nav class="topNavItemBox">
			<div id="ItemBox">
				<div class="title" >肉品溯源管理系统</div>
			</div>
		</nav>
		<!-- 左侧导航 -->
		<#include "left.ftl" />

		<div class="page_main">
			<h3>环境检测管理</h3><span class="add_link"><a href="envInforAdd.ftl">新增环境检测信息></a></span>
			<div class="page_content">
				<h4>环境检测查询</h4>
				<br /><br />
				<form id="environment_query" method="post" action="EnvInforAction_getEnvInfor">
					<label style="width:100px">开始时间</label><input type="text" name="beginTime" id="start_data" data-enable-time=true data-enable-seconds=true class="commonInputtext" /><span></span> 
					<label style="width:100px">结束时间</label><input type="text" name="endTime" id="end_data" data-enable-time=true data-enable-seconds=true class="commonInputtext" /> <span></span>
					<label style="width:100px">采集区域</label><input type="text" name="areaID" id="start_data" class="commonInputtext" />
					<input type="submit" value="查询" style="display: inline-block; margin-left: 30px;" /> <br />
				</form>
				<div>
					<table id="environment_table" class="table" width="100%">
						<thead>
							<tr>
								<th width="30"></th>
								<th width="150">环境信息</th>
								<th width="145">采集类型码</th>
								<th width="150">采集区域码</th>
								<th width="150">企业编号</th>
								<th width="150">传感器类型</th>
								<th width="150">传感器读数</th>
								<th width="150">采集时间</th>
								<th width="80"></th>
							</tr>
						</thead>
						<tbody>
							<tr id="no_data">
								<td width="20"></td>
								<td width="150">暂无数据</td>

							</tr>
						</tbody>
					</table>
				</div>
				<!--<input type="button" id="deleteAllchoice" value="删除所选">-->
				<div id="barcon" name="barcon" style="margin-left: 200px;font-size:10px"></div>
			</div>
			<div class="footer">
				<div class="footer_lineone">
					<span id="logo"></span>肉品溯源管理系统 
					<span class="footer_lineoneSpan"><a href="aboutus.html">关于我们</a></span>
					<span class="footer_lineoneSpan"><a target="_blank" href="http://www.cfsiw.com/">食品安全信息</a></span> 
					<span class="footer_lineoneSpan"><a href="suggestionAdd.ftl">联系我们</a></span>
				</div>
				<div class="footer_linetwo">
					 &copy;2017广东技术师范学院
				</div>
			</div>
		</div>

		<script src="js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery.form.js"></script>
		<script src="js/google-maps.js" type="text/javascript" charset="utf-8"></script>
		<script src="dialog/js/dialog.js"></script>
		<script src="js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/messages_zh.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="flatpickr/flatpickr.js">
		</script>
		<script type="text/javascript" charset="UTF-8">
		$(function() {
			//侧边栏初始化
			$(".vertical-nav").verticalnav({
				speed: 400,
				align: "left"
			});

			//时间控制初始化
			$("#start_data").flatpickr();
			$("#end_data").flatpickr();

			var re_data; //每次传过来的数据

			//查询
			$("#environment_query").ajaxForm(function(data) {
				console.log(data);
				re_data = data;

				//去除暂无数据
				$("#environment_table tbody tr").remove();
				for(var i = 0; i < data.length; i++) {
					var no = i + 1;
					var tb = $("#environment_table tbody");
					var td1 = '<td>' + no + '</td>';
					var td2 = '<td>' + data[i].gid + '</td>';
					var td3 = '<td>' + data[i].envTypeId + '</td>';
					var td4 = '<td>' + data[i].areacodeinfor.areaId + '</td>';
					var td5 = '<td>' + data[i].company.compName + '</td>';
					var td6 = '<td>' + data[i].sensorType.sensorTypeName + '</td>';
					var td7 = '<td>' + data[i].sensorValue + '</td>';
					var td8 = '<td>' + data[i].recordTime.slice(0, 10) + '</td>';
					
					var td_last = '<td><input type="button" onclick="updateData(' + i + ')" class="change" value="更改" style="padding:0 5px"/>'
					var tr_add = '<tr id="environment_row' + data[i].gid + '">' + td1 + td2 + td3 + td4 + td5 + td6 + td7  + td8 + td_last + '</tr>'
					tb.append(tr_add);
				}
				$("#no_data").remove();
				goPage(1,4,"environment_table");
				//console.log($("input[class='change']").val());	
			});

			//更新
			updateData = function(i) {

				var row0 = '<form id="environment_updateform" action="EnvInforAction_UpdateEnv" method="post">'
					var row1 = '<li><label class="labelBeforinput">环境信息</label><input name="gid" readOnly="true" class="bigInputtext" type="text" value="' + re_data[i].gid + '" /></li>';
					var row2 = '<li><label class="labelBeforinput">采集类型码</label><input name="envTypeId" class="bigInputtext" type="text" value="' + re_data[i].envTypeId + '" /></li>';
					var row3 = '<li><label class="labelBeforinput">采集区域码</label><input name="areacodeinfor.areaId" class="bigInputtext" type="text" value="' + re_data[i].areacodeinfor.areaId + '" /></li>';
					var row4 = '<li><label class="labelBeforinput">企业名称</label>'+
						'<select name="company.gid" class="bigInputtext" required data-rule-notZero="true"><option value="'+ re_data[i].company.gid +'">'+ re_data[i].company.compName +'</option>'+'</select>'+
					'</li>';
					
					var row5 = '<li><label class="labelBeforinput">传感器类型</label>'+
						'<select name="sensorType.sensorTypeId" class="bigInputtext" required data-rule-notZero="true"><option value="'+re_data[i].sensorType.sensorTypeId+'">'+ re_data[i].sensorType.sensorTypeName+'</option>'+'</select>'+
					'</li>';
					
					var row6 = '<li><label class="labelBeforinput">传感器读数</label><input name="sensorValue"  class="bigInputtext" type="text" value="' + re_data[i].sensorValue + '" /></li>';
					var row7 = '<li><label class="labelBeforinput">采集时间</label><input name="recordTime" class="bigInputtext" type="text" value="' + re_data[i].recordTime.slice(0, 10) + '" /></li>';
					var rowLast = '</form>'
					var str = row0 + row1 + row2 +row3 + row4 + row5 + row6 + row7 + rowLast;

				
				

				//弹窗
				$.dialog({
					type: 'confirm',
					titleText: '更改数据',
					contentHtml: str,
					onClickOk: function() {
						$("#environment_updateform").ajaxSubmit({
							type: 'post',
							success: function(data) {
								console.log(data);
								//回显
								var row = $("#environment_row" + data.data.gid);
								row.find("td").eq(1).text(data.data.gid);
								row.find("td").eq(2).text(data.data.envTypeId);
									
								row.find("td").eq(3).text(data.data.areacodeinfor.areaId);
								row.find("td").eq(4).text(data.data.company.compName);
								//row.find("td").eq(4).text(data.data.compId);
								row.find("td").eq(5).text(data.data.sensorType.sensorTypeName);
								row.find("td").eq(6).text(data.data.sensorValue);
								row.find("td").eq(7).text(data.data.recordTime.slice(0, 10));
								
								dialogOK();
								re_data[i] = data.data;

								//clearInterval(stopInterval);  
							}
						
						});

					}
				});
				//异步下拉
				$.post("EnvInforAction_getcomp", function(data) {
					console.log(data);
					//$("select[name='vaccineInfor.vaccineId']").empty();
					for(var i = 0; i < data.length; i++) {
						$("select[name='company.gid']").append("<option value='"+ data[i].gid +"'>" + data[i].compName +"</option>");
						}
				});	
				$.post("EnvInforAction_getSensor", function(data) {
					console.log(data);
					//$("select[name='vaccineInfor.vaccineId']").empty();
					for(var i = 0; i < data.length; i++) {
						$("select[name='sensorType.sensorTypeId']").append("<option value='" + data[i].sensorTypeId + "'>" + data[i].sensorTypeName +"</option>");
						}
				});	
				//自动增加
				
/* 					var stopInterval = setInterval(function(){
					var total = $("input[name='quantity']").val()*$("input[name='eachone']").val();
					var finalTotal= $("input[name='discount']").val()*total;
					console.log($("input[name='discount']").val());
					$("input[name='total']").val(total);
					$("input[name='finalTotal']").val(finalTotal);
				},1000); */

				//时间控制器

				$("input[name='recordTime']").flatpickr();
//				$("input[name='expireDate']").flatpickr();
//				$("input[name='produceDate']").flatpickr();
			}

		});
		</script>

	</body>

</html>